'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _radium = require('radium');

var _radium2 = _interopRequireDefault(_radium);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var styles = {
    base: {
        border: '1px solid #FF0000',
        borderRadius: '5px',
        height: '45px'
    },
    back: {}
};

var Header = function (_React$Component) {
    _inherits(Header, _React$Component);

    function Header(props) {
        _classCallCheck(this, Header);

        var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Header).call(this, props));

        _this.state = {
            title: props.title,
            hasBack: props.hasBack
        };

        _this.doBack = _this.doBack.bind(_this);
        return _this;
    }

    _createClass(Header, [{
        key: 'componentWillReceiveProps',
        value: function componentWillReceiveProps(nextProps) {
            if (nextProps.title !== this.props.title) {
                this.setState({ title: nextProps.title });
            }
        }
    }, {
        key: 'doBack',
        value: function doBack() {
            window.history.back();
        }
    }, {
        key: 'renderBackButton',
        value: function renderBackButton() {
            if (this.state.hasBack) {
                return React.createElement(
                    'a',
                    { onClick: this.doBack, style: style.button },
                    '返回'
                );
            }
        }
    }, {
        key: 'render',
        value: function render() {
            var backBtn = void 0;
            if (this.state.hasBack) {
                backBtn = React.createElement(
                    'a',
                    { onClick: this.doBack, style: style.button },
                    '返回'
                );
            }

            return React.createElement(
                'header',
                { style: style.base },
                this.backBtn,
                React.createElement(
                    'h1',
                    null,
                    this.props.title
                )
            );
        }
    }]);

    return Header;
}(React.Component);

;

Header.propTypes = {
    title: _react2.default.PropTypes.string,
    hasBack: _react2.default.PropTypes.bool
};

exports.default = Header;